package o;

import android.util.Base64;
import androidx.annotation.NonNull;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public final class vf<Model, Data> implements vk<Model, Data> {
    private final b<Data> ˎ;

    public interface b<Data> {
        Class<Data> ˎ();

        Data ˏ(String str) throws IllegalArgumentException;

        void ॱ(Data data) throws IOException;
    }

    public static final class c<Model> implements vr<Model, InputStream> {
        private final b<InputStream> ˋ = new b<InputStream>(this) {
            final /* synthetic */ c ˋ;

            {
                this.ˋ = r1;
            }

            public /* synthetic */ Object ˏ(String str) throws IllegalArgumentException {
                return ˎ(str);
            }

            public InputStream ˎ(String str) {
                if (str.startsWith("data:image")) {
                    int indexOf = str.indexOf(44);
                    if (indexOf == -1) {
                        throw new IllegalArgumentException("Missing comma in data URL.");
                    } else if (str.substring(0, indexOf).endsWith(";base64")) {
                        return new ByteArrayInputStream(Base64.decode(str.substring(indexOf + 1), 0));
                    } else {
                        throw new IllegalArgumentException("Not a base64 image data URL.");
                    }
                }
                throw new IllegalArgumentException("Not a valid image data URL.");
            }

            public void ॱ(InputStream inputStream) throws IOException {
                inputStream.close();
            }

            public Class<InputStream> ˎ() {
                return InputStream.class;
            }
        };

        @NonNull
        public vk<Model, InputStream> ˏ(@NonNull vo voVar) {
            return new vf(this.ˋ);
        }

        public void ॱ() {
        }
    }

    static final class d<Data> implements sg<Data> {
        private Data ˊ;
        private final b<Data> ˋ;
        private final String ॱ;

        d(String str, b<Data> bVar) {
            this.ॱ = str;
            this.ˋ = bVar;
        }

        public void ˏ(@NonNull rl rlVar, @NonNull o.sg.d<? super Data> dVar) {
            try {
                this.ˊ = this.ˋ.ˏ(this.ॱ);
                dVar.ॱ(this.ˊ);
            } catch (Exception e) {
                dVar.ˏ(e);
            }
        }

        public void ˏ() {
            try {
                this.ˋ.ॱ(this.ˊ);
            } catch (IOException e) {
            }
        }

        public void ॱ() {
        }

        @NonNull
        public Class<Data> ˋ() {
            return this.ˋ.ˎ();
        }

        @NonNull
        public rz ˎ() {
            return rz.LOCAL;
        }
    }

    public vf(b<Data> bVar) {
        this.ˎ = bVar;
    }

    public o.vk.c<Data> ˎ(@NonNull Model model, int i, int i2, @NonNull sc scVar) {
        return new o.vk.c(new aai(model), new d(model.toString(), this.ˎ));
    }

    public boolean ˋ(@NonNull Model model) {
        return model.toString().startsWith("data:image");
    }
}
